home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / ainet / t2vb432.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1997-07-11  |  11.0 KB  |  255 lines

  1. VERSION 4.00
  2. Begin VB.Form frmMain 
  3.    BorderStyle     =   3  'Fixed Double
  4.    Caption         =   "aiNet DLL & VB40 32 bit; Example #2"
  5.    ClientHeight    =   6420
  6.    ClientLeft      =   1056
  7.    ClientTop       =   1488
  8.    ClientWidth     =   9000
  9.    BeginProperty Font 
  10.       name            =   "MS Sans Serif"
  11.       charset         =   1
  12.       weight          =   700
  13.       size            =   7.8
  14.       underline       =   0   'False
  15.       italic          =   0   'False
  16.       strikethrough   =   0   'False
  17.    EndProperty
  18.    Height          =   6804
  19.    Icon            =   "t2vb432.frx":0000
  20.    Left            =   1008
  21.    LinkTopic       =   "Form1"
  22.    ScaleHeight     =   6420
  23.    ScaleWidth      =   9000
  24.    Top             =   1152
  25.    Width           =   9096
  26.    Begin VB.PictureBox Picture1 
  27.       AutoSize        =   -1  'True
  28.       Height          =   1308
  29.       Left            =   120
  30.       Picture         =   "t2vb432.frx":030A
  31.       ScaleHeight     =   1284
  32.       ScaleWidth      =   7224
  33.       TabIndex        =   3
  34.       Top             =   120
  35.       Width           =   7248
  36.    End
  37.    Begin VB.TextBox tOut 
  38.       BorderStyle     =   0  'None
  39.       BeginProperty Font 
  40.          name            =   "Courier New"
  41.          charset         =   1
  42.          weight          =   400
  43.          size            =   8.4
  44.          underline       =   0   'False
  45.          italic          =   0   'False
  46.          strikethrough   =   0   'False
  47.       EndProperty
  48.       Height          =   4692
  49.       Left            =   120
  50.       MultiLine       =   -1  'True
  51.       TabIndex        =   2
  52.       Top             =   1560
  53.       Width           =   7332
  54.    End
  55.    Begin VB.CommandButton btnExit 
  56.       Caption         =   "E&xit"
  57.       Height          =   375
  58.       Left            =   7620
  59.       TabIndex        =   1
  60.       Top             =   2400
  61.       Width           =   1215
  62.    End
  63.    Begin VB.CommandButton btnStart 
  64.       Caption         =   "&Start"
  65.       Height          =   375
  66.       Left            =   7620
  67.       TabIndex        =   0
  68.       Top             =   1920
  69.       Width           =   1215
  70.    End
  71. Attribute VB_Name = "frmMain"
  72. Attribute VB_Creatable = False
  73. Attribute VB_Exposed = False
  74. Private Sub btnExit_Click()
  75.    End
  76. End Sub
  77. Private Sub btnStart_Click()
  78. '------------------------------------------------------------------------ '
  79. '                                                                         '
  80. '    (C) Copyright 1996 by:  aiNet                                        '
  81. '                            Trubarjeva 42                                '
  82. '                            SI-3000 Celje                                '
  83. '                            Europe, Slovenia                             '
  84. '     All Rights Reserved                                                 '
  85. '                                                                         '
  86. '     Subject: Visual Basic code for single vector prediction.            '
  87. '        File: T2VB432 - The XOR problem with dynamic model creation      '
  88. '       EMAIL: AINET@IKPIR.FAGG.UNI-LJ.SI                                 '
  89. '                                                                         '
  90. ' Last revision: October 17 1996                                          '
  91. '                                                                         '
  92. '-------------------------------------------------------------------------'
  93. '--------------------------------------------------------------------------
  94. '   Here it will be shown how we can solve the XOR problem using
  95. '   aiNet C functions.
  96. '   The XOR problem:
  97. '   ================
  98. '      Number of model vectors: 4
  99. '          Number of variables: 3
  100. '    Number of input variables: 3
  101. '       Any discrete variables: NONE
  102. '      Model vectors:  Inp,Inp,Out
  103. '              row 1:  1,  1,  0
  104. '              row 2:  1,  0,  1
  105. '              row 3:  0,  1,  1
  106. '              row 4:  0,  0,  0
  107. '   Test vectors (vectors which will be used in prediction) together with
  108. '   penalty coefficient and penalty method.
  109. '       Prediction vectors:  Inp  Inp  Out
  110. '                    prd 1:  0.9  0.1  ??
  111. '                    prd 2:  0.1  0.9  ??
  112. '                    prd 3:  0.2  0.2  ??
  113. '                    prd 4:  0.7  0.7  ??
  114. '       Penalty coeffcient: 1.5
  115. '       Penalty methods:    NEAREST
  116. '   NOTE: Selected penalty coefficients are in no case optimal.
  117. '         They were selected randomly, to perform a few tests.
  118. '         The test results were compared with the results calculated by
  119. '         the main aiNet 1.22 application.
  120. '   -----------------------------------------------------------------------
  121. '   Results (rounded at fourth decimal):
  122. '   -----------------------------------------------------------------------
  123. '       Penalty cefficient: 1.5
  124. '       Penalty method:     NEAREST N.
  125. '                                      (RESULT)
  126. '       Prediction vectors:  Inp Inp(Out)
  127. '                    prd 1:  0.9  0.1  (0.9989)
  128. '                    prd 2:  0.1  0.9  (0.9989)
  129. '                    prd 3:  0.2  0.2  (0.1054)
  130. '                    prd 4:  0.7  0.7  (0.3449)
  131. '   -----------------------------------------------------------------------
  132. Dim i As Long
  133. Dim ret As Long                ' dummy for return values
  134.    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  135.    ' Support for text output
  136.    Dim CRNL As String             ' Carriage return + newline
  137.    Dim T As String                ' tab
  138.    Dim TT As String               ' 2 x tab
  139.    CRNL = Chr(13) + Chr(10)
  140.    T = Chr(9)
  141.    TT = Chr(9) + Chr(9)
  142.    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  143.    ' Vectors to be predicted
  144.    ReDim predict(0 To 11) As Single
  145.    predict(0) = 0.9: predict(1) = 0.1: predict(2) = 999
  146.    predict(3) = 0.1: predict(4) = 0.9: predict(5) = 999
  147.    predict(6) = 0.2: predict(7) = 0.2: predict(8) = 999
  148.    predict(9) = 0.7: predict(10) = 0.7: predict(11) = 999
  149.    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  150.    ' Model variable
  151.    Dim model As Long              ' works like a pointer to aiModel structure
  152.    model = 0
  153.    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  154.    ' Title
  155.    ' If Visual Basic fails here saying: can not load DLL ...
  156.    ' copy AINET32.DLL and AINET16.DLL to Windows\System directory!
  157.    version = aiGetVersion()
  158.    major = Int(version / 100)
  159.    minor = version Mod 100
  160.    tOut = "aiNetDLL version " + CStr(major) + "." + CStr(minor)
  161.    tOut = tOut + " (C) Copyright by aiNet, 1996" + CRNL
  162.    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  163.    ' Register DLL
  164.    ret = aiRegistration("Your registration name", "Your code")
  165.    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  166.    ' Allocate the model variable and necessary memory
  167.    ' 4 model vectors
  168.    ' 3 variables
  169.    ' 2 input variables
  170.    ' 1 output variable: 3-2=1 (calculated by aiCreateModel)
  171.    model = aiCreateModel(4, 3, 2)
  172.    If model = 0 Then
  173.       tOut = tOut + CRNL + "Error: Something went wrong during model creation!"
  174.       GoTo End_Sub
  175.    End If
  176.    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  177.    ' Loading data into the model using aiSetVariable function
  178.    ret = aiSetVariable(model, 1, 1, 1#) ' first model vector
  179.    ret = aiSetVariable(model, 1, 2, 1#) ' 1 xor 1 = 0
  180.    ret = aiSetVariable(model, 1, 3, 0#)
  181.    ret = aiSetVariable(model, 2, 1, 1#) ' second model vector
  182.    ret = aiSetVariable(model, 2, 2, 0#) '1 xor 0 = 1
  183.    ret = aiSetVariable(model, 2, 3, 1#)
  184.    ret = aiSetVariable(model, 3, 1, 0#) ' third model vector
  185.    ret = aiSetVariable(model, 3, 2, 1#) ' 0 xor 1 = 1
  186.    ret = aiSetVariable(model, 3, 3, 1#)
  187.    ret = aiSetVariable(model, 4, 1, 0#) ' fourth model vector
  188.    ret = aiSetVariable(model, 4, 2, 0#) ' 0 xor 0 = 0
  189.    ret = aiSetVariable(model, 4, 3, 0#)
  190.    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  191.    ' Output the model
  192.    nVec = aiGetNumberOfModelVectors(model)
  193.    nVar = aiGetNumberOfVariables(model)
  194.    ReDim flag(3) As Long
  195.    flag(1) = aiGetDiscreteFlag(model, 1)
  196.    flag(2) = aiGetDiscreteFlag(model, 2)
  197.    flag(3) = aiGetDiscreteFlag(model, 3)
  198.    tOut = tOut + CRNL + "             Model name: aiNet DLL test 2 (aiCreateModel)"
  199.    tOut = tOut + CRNL + "Number of model vectors: " + CStr(nVec)
  200.    tOut = tOut + CRNL + "    Number of variables: " + CStr(nVar)
  201.    tOut = tOut + CRNL + "         Variable names: A,   B,   A xor B"
  202.    tOut = tOut + CRNL + "          Discrete flag: "
  203.    tOut = tOut + CStr(flag(1)) + "    " + CStr(flag(2)) + "    " + CStr(flag(3))
  204.    ReDim var(3) As Single
  205.    Dim value As Single
  206.    For i = 1 To aiGetNumberOfModelVectors(model) Step 1
  207.       ret = aiGetVariableVB(model, i, 1, value): var(1) = value
  208.       ret = aiGetVariableVB(model, i, 2, value): var(2) = value
  209.       ret = aiGetVariableVB(model, i, 3, value): var(3) = value
  210.       tOut = tOut + CRNL + T + Str(var(1))
  211.       tOut = tOut + TT + Str(var(2))
  212.       tOut = tOut + TT + Str(var(3))
  213.    Next i
  214.    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  215.    ' Normalize the model
  216.    ret = aiNormalize(model, NORMALIZE_REGULAR)
  217.    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  218.    ' Prediction
  219.    ' This test has nearest neighbour penalty coefficient 1.50
  220.    tOut = tOut + CRNL + CRNL + "   Penalty coefficient : 1.50"
  221.    tOut = tOut + CRNL + "         Penalty method: NEAREST N."
  222.    tOut = tOut + CRNL + CRNL + T + "A(inp)" + TT + "B(inp)" + TT + "A xor B(out)"
  223.    ReDim pre(3) As Single
  224.    For i = 0 To 3 Step 1
  225.       ret = aiPrediction(model, predict(i * 3), 1.5, PENALTY_NEAREST)
  226.       pre(1) = predict(i * 3 + 0)
  227.       pre(2) = predict(i * 3 + 1)
  228.       pre(3) = predict(i * 3 + 2)
  229.       ' If the output is not what it should be, you may try to change
  230.       ' the formating argument in Format$ functions below or ...
  231.       tOut = tOut + CRNL + T + CStr(Format$(pre(1), "0.0"))
  232.       tOut = tOut + TT + CStr(Format$(pre(2), "0.0"))
  233.       tOut = tOut + TT + CStr(Format$(pre(3), "0.0000"))
  234.       ' ... simply comment out lines below and comment lines above however,
  235.       ' the output will not look very nice.
  236.       ' The Format$ function is locale depended - depends on the
  237.       ' settings in your computer (Control Panel)
  238.       ' tOut = tOut + CRNL + T + Str(pre(1))
  239.       ' tOut = tOut + TT + Str(pre(2))
  240.       ' tOut = tOut + TT + Str(pre(3))
  241.    Next
  242.    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  243.    ' Denormalize the model (in this case it is not necessary)
  244.    ret = aiDenormalize(model)
  245.    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  246.    ' We must call the aiDeleteModel function here since the
  247.    ' model was allocated dynamicaly using the aiCreateModel
  248.    ' function.
  249.    ret = aiDeleteModel(model)
  250.    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  251.    ' End
  252.    tOut = tOut + CRNL + CRNL + "End."
  253. End_Sub:
  254. End Sub
  255.